package cn.xo68.ide.plugin.common.ui.generate;

import cn.xo68.ide.plugin.common.swing.treetable.CheckContextProvider;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;

import javax.swing.event.ChangeEvent;

/**
 * 代码生成树表节点
 * @author wuxie
 * @date 2018-11-25
 */
public class CodeGenerateNode extends DefaultMutableTreeTableNode {

    protected transient final ChangeEvent checkStateChangeEvent;

    public CodeGenerateNode(CheckContextProvider userObject) {
        this(userObject, null);
    }
    public CodeGenerateNode(CheckContextProvider userObject, ChangeEvent checkStateChangeEvent) {
        super(userObject);
        this.checkStateChangeEvent = checkStateChangeEvent;
    }

    @Override
    public Object getValueAt(int i) {
        if(this.userObject instanceof CheckContextProvider){
           return  ((CheckContextProvider)this.userObject).getValueAt(i);
        }
        return null;
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public boolean isEditable(int column) {
        if(this.userObject instanceof CodeGenerateTableContext && column == 2){
            return true;
        }
        return false;
    }

    @Override
    public void setValueAt(Object aValue, int column) {
        if(this.userObject instanceof CodeGenerateTableContext){
            switch(column) {
               case 2:
                   ((CodeGenerateTableContext)this.userObject).getContext().setModule(aValue.toString());
            }
        }
    }
}
